<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
    <style>
    	required_sign{
    		color: red;
    	}
    </style>
<head>
<body>
<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false">
			<form action="addArticleDetial" id="dataform">
			   <input type="hidden" name="entity.userId" value="0">
				<input type="hidden" name="entity.articleType" value="1">
				<input class="easyui-validatebox" type="hidden" id="img_id" name="imgId" />
				<input class="easyui-validatebox" type="hidden" id="sound_id" name="soundId" />
				<table class="form-tbl"  cellspacing="0" style="width:100%;height:100%;">
					<tr class="form-tr">
						<td class="form-th" colspan="3" style="color: red;text-align: left;padding-left: 10px;">*表示必填项</td>
					</tr>
					<tr class="form-tr">
						<td class="form-th"><span style="color: red;">*</span>文章标题:</td>
						<td class="form-td" colspan="3">
							<input class="easyui-textbox" name="entity.articleTitle" data-options="required:true" style="width:70%" />
						</td>
					</tr>
					<tr>
						<td class="form-td" colspan="4">
							<!-- 加载编辑器的容器 -->
    							<script id="atricle_container" name="entity.articleContent" type="text/plain">
    							</script>
						</td>
					</tr>
					<tr class= "form-tr">
						<td class= "form-th"><span style="color: red;">*</span>封面</td>
						<td>
                            <input id="file_upload_img" name="file_upload_img" type="button" value="上传">
						</td>
						<td class= "form-td" id="td_showImg">
							封面未上传
						</td>
					</tr>
					<tr class= "form-tr">
						<td class= "form-th"><span style="color: red;">*</span>投稿栏目:</td>
						<td class= "form-td">
							<input id="cmb_category" data-options="required:true,editable:false " class="easyui-combobox" name="entity.categoryId"  />
						</td>
						<td class= "form-td">
							<div id="ismarkPublish" name="entity.markPublish"></div>
						</td>
					</tr>
					<tr class="form-tr">
						<th class="form-th"><span style="color: red;">*</span>文章标签:</th>
						
						<!-- <td class="form-td">
							<input id="comb_pId" class="easyui-combobox" data-options="required:true,editable:false " style="width:170px;"  />
						</td> -->
						
						<td class="form-td" colspan="2">
							<input id="comb_tagId" name="tagId" data-options="required:true,editable:false " class="easyui-combobox" style="width:170px;"  />
						</td>
					</tr>
					<tr class="form-tr">
						<th class="form-th">提示:</th>
						<td class="form-td" colspan="3" id="td_showTip">
							
						</td>
					</tr>
					<tr>
						<td colspan="4" style="padding:10px 0px;text-align: center;">
							<a id="save_artile" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存发布</a>
							
							<a onclick="pageReload()" href="#" class="easyui-linkbutton" style="padding-left:10px;" data-options="iconCls:'icon-undo'">清除</a>
							
						</td>
					</tr>
				</table>
			</form>
		</div>
</div>
<script type="text/javascript">
//合并多个空白为一个空白  
String.prototype.ResetBlank = function() {        //对字符串扩展
    var regEx = /\s+/g;  
    return this.replace(regEx, ' ');  
}; 

//初始化编辑器
var item = {  
			toolbars: [
			    [
			        'undo', //撤销
			        'bold', //加粗
			        'indent', //首行缩进
			        'italic', //斜体
			        'underline', //下划线
			        'horizontal', //分隔线
			        'fontfamily', //字体
			        'fontsize', //字号
			        'paragraph', //段落格式
			        'simpleupload', //单图上传
			        'justifyleft', //居左对齐
			        'justifyright', //居右对齐
			        'justifycenter', //居中对齐
			        'justifyjustify', //两端对齐
			        'forecolor', //字体颜色
			        'backcolor', //背景色
			        'insertorderedlist', //有序列表
			        'insertunorderedlist', //无序列表
			        'fullscreen', //全屏
			        'imagenone', //默认
			        'imageleft', //左浮动
			        'imageright', //右浮动
			        'imagecenter', //居中
			        'lineheight', //行间距
			        'edittip ', //编辑提示
			        'customstyle', //自定义标题
			        'drafts', // 从草稿箱加载
			        'preview', //预览
			    ]
			],  
			  imagePopup:true,
	          autoHeightEnabled: false, //是否自动长高，默认true  
	          autoFloatEnabled: false, //是否保持toolbar的位置不动，默认true  
	          wordCount: true, //是否开启字数统计 默认true  
	          maximumWords: 100000, //允许的最大字符数 默认值：10000  
	          wordOverFlowMsg: "<span style='color:red'>超出范围了！！！！！！！！</span>", //超出字数限制提示  
	          elementPathEnabled: false, //是否启用元素路径  
	          padding: 0,  
	          saveInterval: 5000, // 将其设置大点，模拟去掉自动保存功能  
	          allowDivTransToP: false ,
	          initialFrameHeight: 400, //初始化编辑器高度，默认320
	      }; 
	//传参生成实例  
	var ue = UE.getEditor('atricle_container',item);       
	UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;  
	UE.Editor.prototype.getActionUrl = function(action) { 
	    if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {  
	        return '/uEditor/upload';  
	    } else {  
	        return this._bkGetActionUrl.call(this, action);  
	    }  
	} 
$(function(){
	$('#ismarkPublish').radiobox({name:'entity.markPublish',value:true,data:[[true,'公开'],[false,'私密']]});
	//投稿
    $("#cmb_category").combobox({
			url:'${ctx}/category/info/findAll',
			method:'post',
			valueField:'id',
			textField:'name',
			panelHeight:'auto',
			mode:'remote',
		});
	//类型
	$("#comb_tagId").combobox({
		url:'${ctx}/tag/info/findByPidToTag?pid=0',
		method:'get',
		valueField:'id',
		textField:'tagName',
		panelHeight:'auto'
	});
	$("#file_upload_img").on('click',function(){
		toDeploy("jpg,png");
	});
	//添加界面的附件管理
	function toDeploy(extensions){
		showUpload({title:'上传封面'
			,options:{
				filters:{
					mime_types: [{title : "封面图片", extensions : extensions}]
				},
				multi_selection: false ,
				 init:{
					 FileUploaded:function(uploader,file,responseObject){
						 var response = responseObject.response;
						 var json = eval('(' + response + ')');
						 var data = json.data;
						 var path = data.fileUrl;
						 console.log(data);
						 console.log(data.id);
						 $("#img_id").val(data.id);  //完成后更新已上传的文件列表
						 showImg(path);
					 }
				},
				complete:function(){
					top.$ok('上传成功');
				}
			}
		});
	}
	function showImg(path){
		var html = '<img src="'+path+'" style="width:60px;heigth:60px;">';
		$("#td_showImg").html(html);
	}
	
	$("#save_artile").on("click",function(){
		var tip = $("#td_showTip").html("");;
		//获取富文本的内容
		var content = ue.getContent();
		var articleContent = content.ResetBlank();
		$("#articleContent").val(content.ResetBlank());
		var imgId = $("#img_id").val();
		var cmb_category = $("#cmb_category").combobox("getText");
		if(cmb_category == "每日听"){
			var div_tip = '<span style="color: red;">非音频文件不能投稿到每日听，请选择其他投稿栏目</span>';
			tip.append(div_tip);
			return;
		}
		var isValid = $('#dataform').form('enableValidation').form('validate');
		if(!isValid){
			var div_tip = '<span style="color: red;">请完善文章必填信息</span>';
			tip.append(div_tip);
			return;
		}
		if(articleContent.length<1){
			var div_tip = '<span style="color: red;">请添加文章的内容</span>';
			tip.append(div_tip);
			return;
		}
		if(imgId.length<1){
			var div_tip = '<span style="color: red;">请上传文章的封面</span>';
			tip.append(div_tip);
			return;
		}
		toSave();
	});
	
	function toSave(){
		$.messager.progress({title:'系统提示',text:'数据处理中，请耐心等待...'});
		$.submit('#dataform',function(r) {
			$.messager.progress('close');
			if(r.code<0) return $alert(r.msg);
			//top.$prompt('保存成功');
			confirm();
		});
	}
});
function confirm(){
	$.messager.confirm('提示', '添加成功是否继续发布', function(r){
		if (r){
			 window.location.reload();
		}
	});
}
function pageReload(){
	window.location.reload();
}
</script>	
</body>
</html>